package cn.iocoder.yudao.module.social.controller.app.interaction;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.social.controller.admin.interaction.vo.InteractionCreateReqVO;
import cn.iocoder.yudao.module.social.controller.admin.interaction.vo.InteractionRespVO;
import cn.iocoder.yudao.module.social.convert.interaction.InteractionConvert;
import cn.iocoder.yudao.module.social.dal.dataobject.interaction.InteractionDO;
import cn.iocoder.yudao.module.social.service.interaction.InteractionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 APP - 互动")
@RestController
@RequestMapping("/social/interaction")
@Validated
public class AppInteractionController {

    @Resource
    private InteractionService interactionService;

    @PostMapping("/create")
    @Operation(summary = "创建互动")
    public CommonResult<Long> createInteraction(@Valid @RequestBody InteractionCreateReqVO createReqVO) {
        // 设置当前登录用户
        createReqVO.setUserId(getLoginUserId());
        return success(interactionService.createInteraction(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除互动")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteInteraction(@RequestParam("id") Long id) {
        interactionService.deleteInteraction(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得互动")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<InteractionRespVO> getInteraction(@RequestParam("id") Long id) {
        InteractionDO interaction = interactionService.getInteraction(id);
        return success(InteractionConvert.INSTANCE.convert(interaction));
    }

    @GetMapping("/list-by-content")
    @Operation(summary = "根据内容获得互动列表")
    @Parameter(name = "contentId", description = "内容编号", required = true, example = "1024")
    public CommonResult<List<InteractionRespVO>> getInteractionListByContent(@RequestParam("contentId") Long contentId) {
        List<InteractionDO> list = interactionService.getInteractionListByContent(contentId);
        return success(InteractionConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/my-list")
    @Operation(summary = "获得我的互动列表")
    public CommonResult<List<InteractionRespVO>> getMyInteractionList() {
        List<InteractionDO> list = interactionService.getInteractionListByUser(getLoginUserId());
        return success(InteractionConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/list-by-type")
    @Operation(summary = "根据类型获得互动列表")
    @Parameter(name = "type", description = "互动类型", required = true, example = "comment")
    public CommonResult<List<InteractionRespVO>> getInteractionListByType(@RequestParam("type") String type) {
        List<InteractionDO> list = interactionService.getInteractionListByType(type);
        return success(InteractionConvert.INSTANCE.convertList(list));
    }

}
